<?php

namespace App\Http\Controllers\Home;
//引入购物车工具类
use App\Tools\Cart;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Models\Course;

class CourseController extends Controller
{
    //课程详情页
    public function detail(Request $request,$course_id){
        $course = Course::where('course_id',$course_id)->first();
        $course = Course::where('course_id',$course_id)->with(['lesson'=>function($query){
            $query->with('teacher');
        }])->first();
        return view('home.course.detail',compact('course'));
    }

    //购物车添加成功显示页
    public function cart_add(Request $request,Course $course){
        //将商品信息添加到购物车类
        $goods_info = [
            'course_id'   => $course->course_id,
            'course_name' => $course->course_name,
            'course_price'=> $course->course_price
        ];
        $cart = new Cart();
        $cart->add($goods_info);
        return view('home.course.cart_add',compact('course'));
    }
}
